import { createContext, useContext, ReactNode, RefObject } from "react";

interface RefBodyContextType {
  refBody: RefObject<HTMLBodyElement> | null;
}

const BodyRefContext = createContext<RefBodyContextType | null>(null);

export const BodyRefProvider = ({
  children,
  refBody,
}: {
  children: ReactNode;
  refBody: RefObject<HTMLBodyElement> | null;
}) => {
  return (
    <BodyRefContext.Provider value={{ refBody }}>
      {children}
    </BodyRefContext.Provider>
  );
};

export const useRefBodyValue = () => {
  const context = useContext(BodyRefContext);
  return context;
};